package com.tanhua.server.controller;


import com.tanhua.server.service.VoiceService;
import com.tanhua.server.vo.VoiceVo;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author fenda xu
 * @Date 2021 3/29/21 10:28 AM
 * @Version 1.0
 */

@RestController
public class VoiceController {
    @Autowired
    private VoiceService voiceService;


    /**
     * 保存语音
     *
     * @param soundFile
     * @return
     */
    @PostMapping("peachblossom")
    public ResponseEntity saveVoice(@RequestBody MultipartFile soundFile) {
        System.out.println(soundFile.getOriginalFilename());
        try {
            Boolean bo = voiceService.saveVoice(soundFile);
            if (bo) {

                return ResponseEntity.ok("上传语音成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }

    /**
     * @return
     */

    /**
     * 返回给前台vo对象
     *
     * @return
     */
    @GetMapping("peachblossom")
    public ResponseEntity<VoiceVo> getVoice() {

        try {
            VoiceVo voiceVo = voiceService.acceptVoice();
            if (voiceVo != null) {
                return ResponseEntity.ok(voiceVo);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

    }
}
